<?php


namespace app\supplier\controller;


use app\erp\model\MonthContractdb;

class MonthContract extends Base
{
    protected $cols = array(
        array(
            'field' => 'id',
            'width' => 40,
            'title' => 'ID',
            'type' => 'checkbox',
            'fixed' => 'left'
        ),
        array(
            'field' => 'month',
            'width' => 160,
            'title' => '日期'
        ),
        array(
            'field' => 'supplier_name',
            'width' => 240,
            'title' => '供应商'
        ),
        array(
            'field' => 'contract_file',
            'width' => 160,
            'title' => '合同文件',
            'templet' => '#contract_fileTpl'
        ),
        array(
            'field' => 'upload_file',
            'width' => 160,
            'title' => '回传文件',
            'templet' => '#upload_fileTpl'
        ),
        array(
            'field' => 'audit',
            'width' => 100,
            'title' => '审核状态',
            'templet' => '#auditTpl'
        ),
        array(
            'field' => 'audit_name',
            'width' => 120,
            'title' => '审核人'
        ),
        array(
            'field' => 'audit_time',
            'width' => 160,
            'title' => '审核时间'
        ),
        array(
            'field' => 'reason',
            'width' => 160,
            'title' => '驳回原因'
        ),
        array(
            'fixed' => 'right',
            'width' => 80,
            'title' => '操作',
            'toolbar' => '#month_contract_tool'
        )
    );
    public $post = array();

    public function _initialize()
    {
        parent::_initialize();
        $request = request();
        $param = $request->param();
        $this->post = $param;
    }

    public function index()
    {
        $this->assign('cols', json_encode($this->cols));
        return $this->fetch();
    }

    public function ajaxList()
    {
        $monthdb = new MonthContractdb();
        $monthdb->param = $this->post;
        $monthdb->param['supplier_id'] = MEMBER_ID;
        $result = $monthdb
            ->order('id desc')
            ->paginate($this->post['limit']);
        $this->layuiReturn($result->items(), $result->total());
    }

    /**
     * Title("上传回调文件")
     */
    public function uploadFile()
    {
        $monthdb = new MonthContractdb();
        $get_contract = $monthdb->find($this->post['id']);
        if ($get_contract) {
            $save_data = [];
            $save_data['audit'] = 3;
            $save_data['upload_file'] = $this->post['file'];
            $get_contract->save($save_data);
        }
        $this->layuiReturn('success');
    }

}